	enum RotationAxes { MouseXAndY, MouseX, MouseY};
	var axes = RotationAxes.MouseXAndY;
	var sensitivityX = 15;
	var sensitivityY = 15;

	var minimumX = -60;
	var maximumX = 60;

	var minimumY = -60;
	var maximumY = 60;

	var rotationX = 0;
	var rotationY = 0;
	
	var originalRotation;
  private var rotating = false;
  private var turned = false;
      
	function Update ( )
	{
    if(!rotating){
      if (axes == RotationAxes.MouseXAndY)
      {
        // Read the mouse input axis
        rotationX += Input.GetAxis("Mouse X") * sensitivityX;
        rotationY += Input.GetAxis("Mouse Y") * sensitivityY;

        rotationX = Mathf.Clamp (rotationX, minimumX, maximumX);
        rotationY = Mathf.Clamp (rotationY, minimumY, maximumY);
        
        var xQuaternion : Quaternion = Quaternion.AngleAxis (rotationX, Vector3.up);
        var yQuaternion : Quaternion = Quaternion.AngleAxis (rotationY, Vector3.left);
        
        transform.localRotation = originalRotation * xQuaternion * yQuaternion;
      }
      else if (axes == RotationAxes.MouseX)
      {
        rotationX += Input.GetAxis("Mouse X") * sensitivityX;
        rotationX = Mathf.Clamp (rotationX, minimumX, maximumX);

        xQuaternion = Quaternion.AngleAxis (rotationX, Vector3.up);
        transform.localRotation = originalRotation * xQuaternion;
      }
      else
      {
        rotationY += Input.GetAxis("Mouse Y") * sensitivityY;
        rotationY = Mathf.Clamp (rotationY, minimumY, maximumY);

        yQuaternion = Quaternion.AngleAxis (rotationY, Vector3.left);
        transform.localRotation = originalRotation * yQuaternion;
      }
    }
	}
	
	function Start ()
	{
		// Make the rigid body not change rotation
		if (rigidbody)
			rigidbody.freezeRotation = true;
		originalRotation = transform.localRotation;
    }
    
function RotateObject (degrees : Vector3, seconds : float, wait : float){
    if (rotating) return;
    rotating = true;

    var startRotation = transform.rotation;
    var endRotation = transform.rotation * Quaternion.Euler(degrees);
    var t = 0.0;
    var rate = 1.0/seconds;

    while (t < 1.0) {
        t += Time.deltaTime * rate;
        transform.rotation = Quaternion.Slerp(startRotation, endRotation, Mathf.SmoothStep(0.0, 1.0, t));
        yield;
    }
   
   yield WaitForSeconds(wait);
   
    startRotation = transform.rotation;
    endRotation = transform.rotation * Quaternion.Euler(-degrees);
    t = 0.0;
    rate = 1.0/seconds;

    while (t < 1.0) {
        t += Time.deltaTime * rate;
        transform.rotation = Quaternion.Slerp(startRotation, endRotation, Mathf.SmoothStep(0.0, 1.0, t));
        yield;
    }
   
   turned = !turned;
    rotating = false;
}
